'''
学生管理系统

'''
from tkinter.font import names


class User(object):
    # 属性：姓名、年龄、性别、学号
    def __init__(self, name, age, gender, id_number):
        self.name = name
        self.age = age
        self.gender = gender
        self.id_number = id_number

    # 显示信息
    def show_infos(self):
        print("*" * 20)
        print("姓名:%s " % self.name)
        print("年龄:%d " % self.age)
        print("性别:%s " % self.gender)
        print("学(工)号:%d " % self.id_number)


# 学生
class Student(User):
    def __init__(self, name, age, gender, id_number):
        super().__init__(name, age, gender, id_number)

    def show_infos(self):
        super().show_infos()
        print("*" * 20)


# 老师
class Teacher(User):

    # 属性：姓名、年龄、性别、公号、是否是导员、班级列表
    def __init__(self, name, age, gender, id_number, dao, cla):
        super().__init__(name, age, gender, id_number)
        self.dao = dao
        self.cla = cla

    def show_infos(self):
        super().show_infos()
        print("是否是辅导员: %s" % ['否', '是'][self.dao])
        print("辅导班级:")
        if self.cla:
            for i in self.cla:
                print(i)
        else:
            print("空")
        print("*" * 20)


# 班级
class Cla(object):
    # 属性：班级名称、班级号、辅导员、学生
    def __init__(self, name, id_number, teacher, students):
        self.name = name
        self.id_number = id_number
        self.teacher = teacher
        self.students = students

    def show_infos(self):
        print("*" * 15 + "班级信息" + "*" * 15)
        print("班级名称 %s" % self.name)
        print("班级班号 %s" % self.id_number)
        print("辅导员 %s" % self.teacher.name)
        print("学生信息:")
        if self.students:
            for i in self.students:
                print(i.name)
        else:
            print("空")
        print("*" * 15 + "班级信息" + "*" * 15)

    # 添加学生
    def add_student(self, student):
        if student in self.students:
            raise Exception("此学生已经在班级里")
        self.students.append(student)

    # 删除学生
    def sub_student(self, student):
        if student in self.students:
            self.students.remove(student)
            return True
        raise Exception("此学生不在班级里")


# 课程
class Course(object):
    # 属性：课名、课程id、老师、学生列表、课程性质、课程容量
    def __init__(self, name, id_number, teacher, students, type, number):
        self.name = name
        self.id_number = id_number
        self.teacher = teacher
        self.students = students
        self.type = type
        self.number = number
        # 学生数量
        self.student_number = len(students)
        # 剩余名额
        self.valid_number = self.number - self.student_number

    def show_infos(self):
        print("*" * 15 + "课程信息" + "*" * 15)
        print("课程名称 %s" % self.name)
        print("课程号 %s" % self.id_number)
        print("任课老师 %s" % self.teacher.name)
        print("是否是选修课 %s" % self.type)
        print("课程容量 %d" % self.number)
        print("学生数量 %d" % self.student_number)
        print("剩余数量 %d" % self.valid_number)
        print("学生信息:")
        if self.students:
            for i in self.students:
                print(i.name)
        else:
            print("空")
        print("*" * 15 + "课程信息" + "*" * 15)

        # 添加学生

    def add_student(self, student):
        if student in self.students:
            raise Exception("此学生已经在课程里")
        self.students.append(student)

        # 删除学生

    def sub_student(self, student):
        if student in self.students:
            self.students.remove(student)
            return True
        raise Exception("此学生不在课程里")


mia = Student('mia', 19, '女', 1)
mia.show_infos()
rose = Student('rose', 20, '女', 2)

jack = Teacher('jack', 50, '男', 5, False, [])
jack.show_infos()

tom = Teacher('tom', 26, '女', 53, True, ['计算机二班', '法律三班'])
tom.show_infos()

computer_2 = Cla('计算机二班', 1002, tom, [])
computer_2.show_infos()
computer_2.add_student(rose)
computer_2.show_infos()
computer_2.sub_student(rose)
computer_2.show_infos()

computer_1 = Cla('计算机二班', 1002, tom, [mia])
computer_1.show_infos()

python = Course('pyhon', 1, jack, [mia, rose], '必修课', 6)
python.show_infos()